package com.ltxtiyu.video.api;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ltxtiyu.video.common.DataGridParam;
import com.ltxtiyu.video.service.app.VideoService;
import com.ltxtiyu.video.tool.ParamTool;
import com.ltxtiyu.video.tool.Tool;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 素材库
 */
@RestController
public class ApiVideo {
    @Reference
    VideoService videoService;

    /**
     * 素材列表
     * @param request
     * @return
     */
    @RequestMapping("/sourceVideo/list")
    public String sourceVideoList(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("userId",userId);
        return videoService.sourceVideoList(params);
    }

    /**
     * 上传素材
     * @param request
     * @return
     */
    @RequestMapping("/sourceVideo/create")
    public String create(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return videoService.create(params);
    }

    /**
     * 删除自己素材库里的素材
     * @param request
     * @return
     */
    @RequestMapping("/sourceVideo/delete")
    public String delete(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return videoService.delete(params);
    }

    /**
     * 获取分享链接
     * @param request
     * @return
     */
    @RequestMapping("/sourceVideo/sahreLink")
    public String sahreLink(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return videoService.sahreLink(params);
    }

    /**
     * 获取分享视频
     * @param request
     * @return
     */
    @RequestMapping("/sourceVideo/shareVideoList")
    public String shareVideoList(HttpServletRequest request){
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        Integer page = dgp.getPage();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("page", String.valueOf(page));
        return videoService.shareVideoList(params);
    }

}
